package person.learn.sse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Random;

/**
 * 服务器推送技术实现1:服务端发送事件:(sse=Server Send Event)
 * 它默认的请求的URL就是/push
 * Created by barton on 16-5-17.
 */
@Controller
public class SseController {

    @RequestMapping(value = "/push", produces = "text/event-stream")
    @ResponseBody
    public String push() throws InterruptedException {

        Random r = new Random();

        Thread.sleep(5000);

        return "data:Testing 1,2,3" + r.nextInt() + "\n\n";
    }
}
